php forum
php mysql forum
php mysql smarty
 
Topic Options
#104981 - 01/14/04 09:18 AM [Perl] .htaccess and .htpasswd
CTM Offline
Moderator / Da Masta

Registered: 11/23/01
Posts: 2567
I know of the existance of Apache::Htpasswd, which can manage .htpasswd files for Apache servers, but that's not really what I'm looking for.

On a site I'm developing, a user must authenticate him or herself with Apache's basic authentication (.htaccess and .htpasswd). What I'm looking to do is to retrieve the user name the user just logged in with (for use in a personalised greeting). Short of storing a session-long cookie, is there any other way of doing this in Perl?

Top
#104982 - 01/14/04 02:05 PM Re: [Perl] .htaccess and .htpasswd
Charles Capps Offline
Admin Emeritus

Registered: 01/09/00
Posts: 5438
Loc: Lynnwood, WA
Damn... when I saw this topic, I was just gonna pop in here and say "use Apache::Htpasswd" and be done with it. tipsy

Do an %ENV dump... I'm pretty sure that the basic auth string will be somewhere in there. Decode the string using MIME::Base64 to get the username and password.
_________________________
UBB.classic: Love it or hate it, it was mine.

Top
#104983 - 01/14/04 05:56 PM Re: [Perl] .htaccess and .htpasswd
CTM Offline
Moderator / Da Masta

Registered: 11/23/01
Posts: 2567
Ah, $ENV{REMOTE_USER}. Didn't need to be decrypted either. Great stuff. smile

Thanks again Charles. wink

Top
#104984 - 11/02/04 05:50 AM Re: [Perl] .htaccess and .htpasswd
max.mx Offline
Junior Member

Registered: 11/02/04
Posts: 2
Hey, I'm glad I found this topic, probably one of you guys could help me.

I'm loging into a restricted folder using htpasswd/htaccess. Now I access a simple Guestbook, where I want the Username I just use to log in be written in a <input type=text value=???> field (which is part of a cgi-file).

Eventually it would be great to do it like that:
If the htpasswd username is 4 example: "ms2" then it should display in the textfield the Username "Max Smith". Some kina If... then.

Then I could disable the textfield so the user can post only by his real name, according to the htpasswd username he just used.

I'm quite a newbie in that so please explain so that I will understand tipsy


Thanks A LOT!!!
Max

Top
#104985 - 11/02/04 06:18 AM Re: [Perl] .htaccess and .htpasswd
Gizmo Online   shocked

Wizard

Registered: 01/10/00
Posts: 5354
Loc: Portland, OR, USA
Main question would be where would the real name be stored; the .htaccess file ins't meant to be a database of any kind; the way i'd do it is make it php based, then have a small mysql database containing usernames/passwords/real names (you could do flat file too i guess); then you can have it 'if username = jd then realname = John Doe'
_________________________
UBB.Dev - Where you too can render your UBB install completely useless...
UGN Security, Elite Web Gamers & VNC Web Design & Development President
UBB.Threads: My UBBSkins, UBB.Sitemaps

Top
#104986 - 11/02/04 06:20 AM Re: [Perl] .htaccess and .htpasswd
LK Offline
Admin / Code Breaker

Registered: 03/24/01
Posts: 7396
Try:
%names = (
"ms2" => "Max Smith",
"ms1" => "Mark Stone",
"tb" => "Tom Bush",
"etc" => "Whatever",
);

Then
print qq~<input type="text" name="name" value="$names{$ENV{REMOTE_USER}}">~;

That's untested but I think it could work.
Note that if it's a type=text, the user can still change the value, but the default one would be from the %names variable.
_________________________

My Hacks Page (will be back with UBB 7!)
UBBDev - We put the class into UBB.classic!

Top
#104987 - 11/02/04 07:05 AM Re: [Perl] .htaccess and .htpasswd
Gizmo Online   shocked

Wizard

Registered: 01/10/00
Posts: 5354
Loc: Portland, OR, USA
I'm always a fan of:
Code:
<input type="hidden" value="">
_________________________
UBB.Dev - Where you too can render your UBB install completely useless...
UGN Security, Elite Web Gamers & VNC Web Design & Development President
UBB.Threads: My UBBSkins, UBB.Sitemaps

Top
#104988 - 11/02/04 07:25 AM Re: [Perl] .htaccess and .htpasswd
LK Offline
Admin / Code Breaker

Registered: 03/24/01
Posts: 7396
But then they can still modify it by going to the code...
You can give them a 12-char session id, so that they'll have almost no way to change it to another true one. Create a sessions.cgi file in the directory, have a randomly-generated id such as "Fr5g4Dds9aG", in the file have "Fr5g4Dds9aG" => "Max Smith", and then add to the HTML: input type="hidden" name="session" value="Fr5g4Dds9aG".

But that's only if you don't trust them. smile
_________________________

My Hacks Page (will be back with UBB 7!)
UBBDev - We put the class into UBB.classic!

Top
#104989 - 11/02/04 12:15 PM Re: [Perl] .htaccess and .htpasswd
max.mx Offline
Junior Member

Registered: 11/02/04
Posts: 2
Thanks guys, you really helped me a lot!

Your script works fine, LK rockon

I just added a 0nfocus="this.blur()" within the textfield, thats enough for my purposes...
The guestbook is just for about 30 people, no one with a good cgi-knowledge and surely not intending to manipulate those variables... so I don't think I'll have to do further scripting wink

byebye and thanks again,
Max

Top



Latest Posts
[7.2.1] - Naked shoutbox
by bellaonline
05/05/12 05:00 PM
[7.x] Stop Forum Spam Integration v0.4
by bellaonline
05/05/12 03:53 PM
Shout Box

(Views)Popular Topics
Known public proxy servers 1689885
Integrated Index Page (IIP) 5.3.1 555705
Finished-[6.5.2] Games Arcade Deluxe v1.9 501236
Integrated Index Page (IIP) 5.1.1 415112
TLD Bv2.1 Released - Threads Links Directory 396822
[6.0x] Who's Online 4.0.0 [Finished] 389412
Finished-[6.5.1] Integrated Index Page (IIP) 6.5 330423
Q & A 298663
Slash UBB 266936
[6.3.x] [beta] Hit Hack 2.0 227970
Forum Stats
13621 Members
59 Forums
37191 Topics
295716 Posts

Max Online: 686 @ 06/28/07 07:04 AM

 

 

 
fusionbb message board php hacks